$(document).ready(
 	function () {
 	    $("#mainsearchinput").keypress(function (event) {
 	        var keyCode = event.which;
 	        if (keyCode == 13) {
 	            topsearch();
 	        }
 	    })
 	    $("#keyM").keypress(function (event) {
 	        var keyCode = event.which;
 	        if (keyCode == 13) {
 	            suppliersearch();
 	        }
 	    })
	}
)

//top搜索
function topsearch()
{
	var searchvalue = "";
	searchvalue = $("#mainsearchinput").val().Trim();
	var searchtype = $("#mainsearchtype").val();
	if (searchvalue.length > 50) {
		$("#mainsearchinput").attr("value", "");
 	    return false;
	}
	else
	{				
		var param = "?keyword=" + searchvalue + "";
		if (searchvalue == "")
		{
			param = "";
		}
		if(searchtype == "建材")
		{
			window.location.href = "/temp/search/product.html" + param;
		}
		else if(searchtype == "供应商")
		{
			window.location.href = "/temp/search/supplier.html" + param;
		}
	}
}

//材料搜索
function productsearch()
{
	var searchname = "";
	var searchbrand = "";
	var searchspec = "";
	var searchsupplier = "";
	var searchlprice = "";
	var searchhprice = "";
	var searchdate = "";
	searchname = $("#searchName").val().Trim();
	searchbrand = $("#searchBrand").val().Trim();
	searchspec = $("#searchSpec").val().Trim();
	searchsupplier = $("#searchManufacturer").val().Trim();
	searchlprice = $("#searchlPrice").val().Trim();
	searchhprice = $("#searchhPrice").val().Trim();
	searchdate = $("#searchDate").val().Trim();
	
	var flag = true;
	if (searchname.length > 50) {
		$("#searchName").attr("value", "");
 	    flag =  false;
	}
	if (searchbrand.length > 50) {
		$("#searchBrand").attr("value", "");
 	    flag =  false;
	}
	if (searchspec.length > 50) {
		$("#searchSpec").attr("value", "");
 	    flag =  false;
	}
	if (searchsupplier.length > 50) {
		$("#searchManufacturer").attr("value", "");
 	    flag =  false;
	}
	if (searchlprice.length > 50) {
		$("#searchlPrice").attr("value", "");
 	    flag =  false;
	}
	if (searchhprice.length > 50) {
		$("#searchhPrice").attr("value", "");
 	    flag =  false;
	}
	if(flag == false)
	{
		return false;
	}
	else{
		var param = "?kwName=" + searchname + "&kwBrand=" + searchbrand + "&kwSpec=" + searchspec + "&kwSupplier=" + searchsupplier + "&kwlPrice=" + searchlprice + "&kwhPrice=" + searchhprice + "&kwDay=" + searchdate;
		window.location.href = "/temp/search/product.html" + param;
	}
}

//供应商搜索
function suppliersearch()
{
	var searchvalue = "";
	searchvalue = $("#keyM").val().Trim();
	if (searchvalue.length > 50) {
		$("#keyM").attr("value", "");
 	    return false;
	}
	else
	{				
		var param = "?keyword=" + searchvalue;
		if (searchvalue == "")
		{
			param = "";
		}
		
		window.location.href = "/temp/search/supplier.html" + param;
	}
}

//供应商详情的材料搜索
function supplierinfosearchproduct()
{
	var searchvalue = "";
	var spec = "";
	searchvalue = $("#productName").val().Trim();
	spec = $("#productSpec").val().Trim();
	if (searchvalue.length > 50) {
		$("#productName").attr("value", "");
 	    return false;
	}
	if (spec.length > 50) {
		$("#productSpec").attr("value", "");
 	    return false;
	}
	
	//获得当前供应商ID
	var myurl=new UrlEdit.URL(document.URL);
	var _id = "";		
	if(myurl.get("id") != undefined && myurl.get("id") != "")
	{
		_id = myurl.get("id");
	}
	if(_id == "")
	{
		window.location.href="/temp/search/supplier.html";
	}
	
	var param = "?id=" + _id + "&keyword=" + searchvalue + "" + "&spec=" + spec;
	
	window.location.href = "/temp/supplierinfo.html" + param;
}

//去掉参数前后“”
function removequote(str)
{
	return str;
	if (str == "" || str == undefined)
	{
		return "";
	}
	else
	{
		var length = str.length;
		return str.substring(1, length - 1);
	}
}

function returnidurl(type, id)
{
	var ret = "/temp/" + type + "?id=" + encodeURIComponent(id);
	return ret;
}

function addprop(props, propname, propvalue)
{
	return (props + propname + ":" + propvalue + ";");
}

function removeprop(props, propname)
{
	var newprops = "";
	var propArr = props.split(';');
	for (var i = 0; i < propArr.length; i++)
	{
		var prop = propArr[i];
		if (prop != "")
		{
			var name = prop.split(':')[0];
			if (name != propname)
			{
				newprops = newprops + prop + ";"
			}
			
		}
	}
	return newprops;
}

function initprops(props)
{
	var newprops = new Array();
	var propArr = props.split(';');
	for (var i = 0; i < propArr.length; i++)
	{
		var prop = propArr[i];
		if (prop != "")
		{
			var name = prop.split(':')[0];
			var value = prop.split(':')[1];
			var newprop = new Object();
			newprop["name"] = name;
			newprop["value"] = value;
			newprops.push(newprop);
		}
	}
	return newprops;
	
}